import { CommandDialog } from '@amcax/base';
import { i18n } from '@app-nextmesh/common/utils';
import { NMTopoBaseCommand } from '@app-nextmesh/types/command';
import { MsComponent } from '../cmd-common/component';
import { RJSFSchema } from '@rjsf/utils';
import { PickInputRJSFFormat } from '@app-cad/common/components/command-form/constants';
import { getNormalsOrIds } from '../cmd-common/tools';
interface PointCommandProps {
  title: string;
  onClose: () => void;
}
const setSchema: RJSFSchema = {
  type: 'object',
  properties: {
    source: {
      type: 'array',
      items: {
        type: 'string',
        enum: [],
      },
      format: PickInputRJSFFormat.MultiPickCurve,
      uniqueItems: true,
    },
  },
};
const extraUiSchema = {
  source: {
    'ui:placeholder': '选择孔的边',
    'ui:autofocus': true,
  },
};
const formatFn = (formData) => {
  const ids = getNormalsOrIds(formData.source, 'id').map((it) => it.id);
  return {
    source: ids,
  };
};
// source
function FillHoleCommand({ onClose, title }: PointCommandProps) {
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <MsComponent
        onClose={onClose}
        formatParam={formatFn}
        formParams={{
          schemaParams: setSchema,
          extraUiSchema: extraUiSchema,
        }}
        wsApi={'fillHole'}
      />
    </CommandDialog>
  );
}
export const cmdFillHole: NMTopoBaseCommand = {
  id: 'CmdFillHole',
  label: 'command.topo.fill-hole',
  icon: 'commands/curved/fill',
  create: function (label: string, onClose: () => void) {
    return (
      <FillHoleCommand
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
